Load some packages that we’ll need to use to do these calculations:

library(tidyverse)
library(gifski)
library(ggraph)
library(here)
library(igraph)
library(tnet) # for the closeness function described here: https://toreopsahl.com/2010/03/20/closeness-centrality-in-networks-with-disconnected-components/
source(here("modelFunction_rewiring.R"))

1. Run the model once

# Define parameters
N = 50
edge.prob <- 0.04
n.removed = 10
burn.in = 20
recovery = 5
add00 = c(0.5, 10)
lose01 = 0.1
add10 = 0.05
lose11 = c(0.5, 0.5)
coefAdd = 0.5
coefLose = -0.5
modelGraphs <- runModel(N = N, # Nodes in the network
                        edge.prob = edge.prob,
                        n.removed = n.removed,
                        burn.in = burn.in,
                        recovery = recovery,
                        add00 = add00, 
                        lose01 = lose01, 
                        add10 = add10,
                        lose11 = lose11,
                        coefAdd = coefAdd,
                        coefLose = coefLose)$graphs

2. For a single model run, examine network-level measures over time

## Warning: Removed 1 row(s) containing missing values (geom_path).

4. Relationship between removed nodes and network-level measures

## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
## Using compatibility `.name_repair`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.

A few sanity checks:

What about the ratio between the first and second changes? Aka: what percentage of the loss/gain is recovered by the rewiring?

## Warning in log(ratio): NaNs produced

## Warning in log(ratio): NaNs produced

## Warning in log(ratio): NaNs produced
## Warning: Removed 883 rows containing non-finite values (stat_smooth).
## Warning: Removed 862 rows containing missing values (geom_point).

## Warning in log(ratio): NaNs produced
## Warning in log(ratio): NaNs produced

## Warning in log(ratio): NaNs produced
## Warning: Removed 883 rows containing non-finite values (stat_smooth).
## Warning: Removed 862 rows containing missing values (geom_point).

## Warning in log(ratio): NaNs produced
## Warning in log(ratio): NaNs produced

## Warning in log(ratio): NaNs produced
## Warning: Removed 883 rows containing non-finite values (stat_smooth).
## Warning: Removed 862 rows containing missing values (geom_point).

## Warning: Removed 21 rows containing non-finite values (stat_smooth).

## Warning: Removed 21 rows containing non-finite values (stat_smooth).

## Warning: Removed 21 rows containing non-finite values (stat_smooth).